﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HRM.DAL.DAO;
using HRM.DAL.Gateway;
using HRM.DAL.Report;

namespace HRM.BLL
{
    public class EvaluationManager
    {
        EvaluationGateway gateway=new EvaluationGateway();
        public bool EvaluateEmployee(Evaluation evaluation)
        {
            EmployeeManager empManager=new EmployeeManager();
            int empId = empManager.GetEmployeeID(evaluation.Employee.EmpCode);
            ProjectManager projectManager=new ProjectManager();
            int pmId = projectManager.GetProjectManagerId(evaluation.Pm.Id);
            return gateway.SaveEvaluation(empId,pmId,evaluation);
        }
        public bool EditEvaluation(Evaluation evaluation)
        {
            EmployeeManager empManager = new EmployeeManager();
            int empId = empManager.GetEmployeeID(evaluation.Employee.EmpCode);
            return gateway.EditEvaluation(empId, evaluation);
        }
        public SingleEmployeEvaluationReport GetEmployeesEvaluation(Code code)
        {
            EmployeeManager empManager = new EmployeeManager();
            SingleEmployeEvaluationReport evaluation=new SingleEmployeEvaluationReport();
            evaluation= gateway.GetEmployeesEvaluation(code);
            int pmId = Convert.ToInt32(evaluation.Pm);
            string pmName = empManager.GetEmployeeName(pmId);
            evaluation.Pm = pmName;
            return evaluation;
        }

        public List<SingleEmployeEvaluationReport> GetEvaluationReport(Project project)
        {
            EmployeeManager empManager = new EmployeeManager();
            List<SingleEmployeEvaluationReport> reports=new List<SingleEmployeEvaluationReport>();
            reports = gateway.GetEvaluationReport(project);

            int pmId = Convert.ToInt32(reports[3].Pm);
            string pmName = empManager.GetEmployeeName(pmId);

            foreach (SingleEmployeEvaluationReport report in reports)
            {
                reports[3].Pm = pmName;
            }
           
            return reports;
        }

    }
}